﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XCommon.Types;

namespace XDAL
{
    public class tbOrder : tbBase<tbOrder>
    {

        private const string SQL_INSERT = "INSERT INTO tborder(type,count,number,date,userid) VALUES(@" +
            XModel.Keys.KEY_TBORDER_TYPE + ",@" +
            XModel.Keys.KEY_TBORDER_COUNT + ",@" +
            XModel.Keys.KEY_TBORDER_NUMBER + ",now(),@" +
            XModel.Keys.KEY_TBORDER_USERID + ") ";

        private const string SQL_SELECT = "SELECT * FROM tborder WHERE userid = @userid ORDER BY userid ASC";

        public bool Insert(Ps ps)
        {
            List<MySql.Data.MySqlClient.MySqlParameter> para = new List<MySql.Data.MySqlClient.MySqlParameter>();
            foreach (KeyValuePair<string, string> item in ps)
            {
                para.Add(new MySql.Data.MySqlClient.MySqlParameter("@" + item.Key, item.Value));
            }
            return MySQL.MySqlHelper.ExecuteNonQuery(SQL_INSERT, para.ToArray()) > 0;
        }

        public List<Ps> Get(int userid)
        {
            MySql.Data.MySqlClient.MySqlParameter[] para = new MySql.Data.MySqlClient.MySqlParameter[]{
                new  MySql.Data.MySqlClient.MySqlParameter("@userid",userid)
            };
            List<Ps> list = MySQL.MySqlHelper.ReadToList(MySQL.MySqlHelper.ExecuteReader(SQL_SELECT, para));
            return list;
        }
    }
}
